namespace pos.entity
{
using System;
using System.Data;
using System.Configuration;
using System.Text;
using System.Data.OleDb;
using System.Collections;
using System.Windows.Forms;
using NHibernate;
using NHibernate.Criterion;
/// <summary>
/// t_setting 的摘要说明
/// </summary>
public class t_setting:IEntityUtil
{
//   数据类型值的哈希表 
	private static Hashtable m_enum_type;
	public static Hashtable  enum_type
	{
		get{return m_enum_type;}
	}
	public const int INTTYPE=1;
	public const int CHARTYPE=2;
//   参数类别值的哈希表 
	private static Hashtable m_enum_catalog;
	public static Hashtable  enum_catalog
	{
		get{return m_enum_catalog;}
	}
	public const int NOTES=1;
	public const int LABEL=2;
	//   列名称哈希表 
	private static Hashtable m_colLabels;    	 
	public static Hashtable colLabels//
	{
		get{return m_colLabels;}
	}
	//表字段名称哈希表
	private static ArrayList m_colNames;     
	public static ArrayList  colNames　
	{
		get{return m_colNames;}
	}
	private Setting __setting;
	public long seqID  
	{
		get{return __setting.seqID;}
		set{ __setting.seqID=value;}
	}
	public String id  
	{
		get{return __setting.id;}
		set{ __setting.id=value;}
	}
	public String name  
	{
		get{return __setting.name;}
		set{ __setting.name=value;}
	}
	public int type  
	{
		get{return __setting.type;}
		set{ __setting.type=value;}
	}
	public int catalog  
	{
		get{return __setting.catalog;}
		set{ __setting.catalog=value;}
	}
	public String value  
	{
		get{return __setting.value;}
		set{ __setting.value=value;}
	}
	private static  SettingDao dao=(SettingDao)SpringContext.Context.GetObject("SettingDao");
	public static SettingDao DAO
	{
		get{return dao;}
		
	}
	
	public t_setting()
	{
		__setting=new Setting();
	  	seqID=consts.long_min;
	  	id="";
	  	name="";
	  	type=consts.int_min;
	  	catalog=consts.int_min;
	  	value="";
	  // dao=(SettingDao)SpringContext.Context.GetObject("SettingDao");
	   if(m_colLabels==null)
	   {
		m_colLabels = new Hashtable();
        m_colNames= new ArrayList();
		m_colLabels.Add("seqID", @"序号");
		colNames.Add("seqID");
		m_colLabels.Add("id", @"参数英文名");
		colNames.Add("id");
		m_colLabels.Add("name", @"参数名");
		colNames.Add("name");
		m_colLabels.Add("type", @"数据类型");
		colNames.Add("type");
		m_enum_type= new Hashtable();
		m_enum_type.Add("1", @"数字");
		m_enum_type.Add("2", @"字符");
		m_colLabels.Add("catalog", @"参数类别");
		colNames.Add("catalog");
		m_enum_catalog= new Hashtable();
		m_enum_catalog.Add("1", @"票据");
		m_enum_catalog.Add("2", @"标签");
		m_colLabels.Add("value", @"参数值");
		colNames.Add("value");
	  }
	
	}
	public t_setting(Setting entity )
	{
		__setting=entity;
		
	  // dao=(SettingDao)SpringContext.Context.GetObject("SettingDao");
	   if(m_colLabels==null)
	   {
		m_colLabels = new Hashtable();
        m_colNames= new ArrayList();
		m_colLabels.Add("seqID", @"序号");
		colNames.Add("seqID");
		m_colLabels.Add("id", @"参数英文名");
		colNames.Add("id");
		m_colLabels.Add("name", @"参数名");
		colNames.Add("name");
		m_colLabels.Add("type", @"数据类型");
		colNames.Add("type");
		m_enum_type= new Hashtable();
		m_enum_type.Add("1", @"数字");
		m_enum_type.Add("2", @"字符");
		m_colLabels.Add("catalog", @"参数类别");
		colNames.Add("catalog");
		m_enum_catalog= new Hashtable();
		m_enum_catalog.Add("1", @"票据");
		m_enum_catalog.Add("2", @"标签");
		m_colLabels.Add("value", @"参数值");
		colNames.Add("value");
	  }
	
	}
	public Object uniqueResult(DetachedCriteria dc)
    {
        return dao.uniqueResult(dc);
    }
	 public DetachedCriteria DC 
     {
        	get{return DetachedCriteria.For(typeof(Setting));}
     }
	public const string ENTITYNAME="t_setting";
	public const int SEQN0=2;
	
    public void checkAdd()
    {
		int len;
	//try{Convert.ToInt64(seqID);}catch{ throw (new Exception("请输入正确的长整数格式"));		}
		if(	seqID<consts.long_min+1)
			throw (new Exception("请输入序号"));
 if(				(				  string.Format("{0}",seqID)				  )=="0")
	 throw (new Exception("序号是主健，框架要求值不能为0"));				

	
	len=id.Trim().Length;
	if(len>50)
		 throw (new Exception("参数英文名字符长度最长不能超过50,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("参数英文名不能为空!"));	
	

	
	len=name.Trim().Length;
	if(len>50)
		 throw (new Exception("参数名字符长度最长不能超过50,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("参数名不能为空!"));	
	

	//try{Convert.ToInt32(type);}catch{ throw (new Exception("请输入正确的整数格式"));		}
		if(	type<consts.int_min+1)
			throw (new Exception("请输入数据类型"));

	//try{Convert.ToInt32(catalog);}catch{ throw (new Exception("请输入正确的整数格式"));		}
		if(	catalog<consts.int_min+1)
			throw (new Exception("请输入参数类别"));

	
	len=value.Trim().Length;
	if(len>50)
		 throw (new Exception("参数值字符长度最长不能超过50,当前长度为"+len.ToString()));	
	

//unique="yes" 唯一性验证
    }
    public void checkUpdate()
    {
		int len;
	//try{Convert.ToInt64(seqID);}catch{ throw (new Exception("请输入正确的长整数格式"));		}
		if(	seqID<consts.long_min+1)
			throw (new Exception("请输入序号"));
 if(				(				  string.Format("{0}",seqID)				  )=="0")
	 throw (new Exception("序号是主健，框架要求值不能为0"));				

	
	len=id.Trim().Length;
	if(len>50)
		 throw (new Exception("参数英文名字符长度最长不能超过50,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("参数英文名不能为空!"));	
	

	
	len=name.Trim().Length;
	if(len>50)
		 throw (new Exception("参数名字符长度最长不能超过50,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("参数名不能为空!"));	
	

	//try{Convert.ToInt32(type);}catch{ throw (new Exception("请输入正确的整数格式"));		}
		if(	type<consts.int_min+1)
			throw (new Exception("请输入数据类型"));

	//try{Convert.ToInt32(catalog);}catch{ throw (new Exception("请输入正确的整数格式"));		}
		if(	catalog<consts.int_min+1)
			throw (new Exception("请输入参数类别"));

	
	len=value.Trim().Length;
	if(len>50)
		 throw (new Exception("参数值字符长度最长不能超过50,当前长度为"+len.ToString()));	
	

//unique="yes" 唯一性验证
		ICriterion crit=Restrictions.Eq("seqID", seqID);
  		IList list=dao.List(dao.DC.Add(crit));
		if(list.Count==1)
			return;
		if(list.Count==0)
			throw (new Exception("该记录已经被删除"));	
		else
			throw (new Exception("改纪录出现重名!"));
    }
    public void add()
    {
        try
        {
            checkAdd();
         	dao.Add(__setting);
        }
        catch(Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }
   
    public void delByseqID()
    {
    
        try
        {
          dao.Delete(__setting);
        }
        catch(Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }

    public  void update()
    {
        try
        {
            checkUpdate();
            dao.Update(__setting);
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }
   
    public void ExecDataUpdate(int rowNo)
    {
		if(m_updateRow==null)
			return;
		int ii=0;
m_updateRow(rowNo,ii++,				(				  string.Format("{0}",seqID)				  ));	
m_updateRow(rowNo,ii++,name);	
m_updateRow(rowNo,ii++,	t_setting.enum_type[type.ToString()].ToString()
);	
m_updateRow(rowNo,ii++,	t_setting.enum_catalog[catalog.ToString()].ToString()
);	
m_updateRow(rowNo,ii++,value);	

    }
    public void ExecHeadInsert()
    {
		if(m_insertHead!=null)
        {
			int ii=0;
			m_insertHead(ii++,50,"序号");
			m_insertHead(ii++,100,"参数名");
			m_insertHead(ii++,100,"数据类型");
			m_insertHead(ii++,100,"参数类别");
			m_insertHead(ii++,150,"参数值");
		}		
    }
    public void ExecDataInsert()
	{
		if(m_insertRow==null)
			return;
		int ii=0;
     	m_insertRow(0,ii++,				(				  string.Format("{0}",seqID)				  ));
     	m_insertRow(0,ii++,name);
     	m_insertRow(0,ii++,	t_setting.enum_type[type.ToString()].ToString()
);
     	m_insertRow(0,ii++,	t_setting.enum_catalog[catalog.ToString()].ToString()
);
     	m_insertRow(0,ii++,value);
    }
    public void ExecDataInsertByQuery(DetachedCriteria dc)
    {
      
         IList list=dao.List(dc); 
        
        if(m_insertHead!=null)
        {
			int ii=0;
			m_insertHead(ii++,50,"序号");
			m_insertHead(ii++,100,"参数名");
			m_insertHead(ii++,100,"数据类型");
			m_insertHead(ii++,100,"参数类别");
			m_insertHead(ii++,150,"参数值");
		}		
		
      if(m_insertRow!=null)
      {
        int j=0;
        foreach(Setting obj in list)			
        {
		  int ii=0;
	     
m_insertRow(j,ii++,				(				  string.Format("{0}",obj.seqID)
				  )
);
m_insertRow(j,ii++,obj.name.ToString());
m_insertRow(j,ii++,	t_setting.enum_type[obj.type.ToString()].ToString()
);
m_insertRow(j,ii++,	t_setting.enum_catalog[obj.catalog.ToString()].ToString()
);
m_insertRow(j,ii++,obj.value.ToString());
		j++;
        }
        

	
       }
    }

    
    public IList List(DetachedCriteria dc)
    {
        try
        {
           
            return dao.List(dc);
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }
    
    public bool Init(DetachedCriteria dc)
    {
    
    		Setting obj=dao.Get(dc);
    		if(obj==null)
    			return false;
    		else
    		{
    			__setting=obj;
            	return true;
            }
        
    }
    public static t_setting Get(DetachedCriteria dc)
    {
    	
    	Setting obj=((SettingDao)SpringContext.Context.GetObject("SettingDao"))
	 	.Get(dc);
	 	if(obj==null)
	 		return null;
	 	else
	 		return new t_setting( obj );
        
    }
	 public static t_setting GetBySeqID(long val)
	 {
	 	Setting obj=((SettingDao)SpringContext.Context.GetObject("SettingDao"))
	 	.GetBySeqID(val);
	 	if(obj==null)
	 		return null;
	 	else
	 		return new t_setting( obj );
	 	
	 	
	 }
	 public  bool InitBySeqID(long val)
	 {
	 	

	 	Setting obj=dao.GetBySeqID(val) ;
	 	if(obj==null)
	 		return false;
	 	else
	 	{
	 		__setting=obj;
	 		return true;
	 	}
	 	
	 	
	 }
    
       public bool showInForm(Control.ControlCollection Controls)
    {
        try
        {
             
		if(Controls["seqID"]!=null)
		{
			Controls["seqID"].Text=				(				  string.Format("{0}",seqID)				  );
		}
		if(Controls["id"]!=null)
		{
			Controls["id"].Text=id;
		}
		if(Controls["name"]!=null)
		{
			Controls["name"].Text=name;
		}
		if(Controls["type"]!=null)
		{
			Controls["type"].Text=	t_setting.enum_type[type.ToString()].ToString()
;
		}
		if(Controls["catalog"]!=null)
		{
			Controls["catalog"].Text=	t_setting.enum_catalog[catalog.ToString()].ToString()
;
		}
		if(Controls["value"]!=null)
		{
			Controls["value"].Text=value;
		}
			return true;
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
            
        }
    }
    public  t_setting Init(Setting item)
    {
        __setting=item;
        return this;
    }

    
     public bool initByForm(Control.ControlCollection Controls)
    {
        try
        {
             
		if(Controls["seqID"]!=null)
		{
			
			if(Controls["seqID"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["seqID"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{seqID=(v==""?consts.long_min:Convert.ToInt32(v));}
				catch
				{
					 Controls["seqID"].Focus();
					throw  (new Exception("序号格式不正确！！"));
				}
				
			}
			else
			{
				try{seqID=(Controls["seqID"].Text==""?consts.long_min:Convert.ToInt32(Controls["seqID"].Text));}
				catch
				{
					 Controls["seqID"].Focus();
					throw  (new Exception("序号格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["id"]!=null)
		{
			
			if(Controls["id"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["id"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{id=v;}
				catch
				{
					 Controls["id"].Focus();
					throw  (new Exception("参数英文名格式不正确！！"));
				}
				
			}
			else
			{
				try{id=Controls["id"].Text;}
				catch
				{
					 Controls["id"].Focus();
					throw  (new Exception("参数英文名格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["name"]!=null)
		{
			
			if(Controls["name"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["name"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{name=v;}
				catch
				{
					 Controls["name"].Focus();
					throw  (new Exception("参数名格式不正确！！"));
				}
				
			}
			else
			{
				try{name=Controls["name"].Text;}
				catch
				{
					 Controls["name"].Focus();
					throw  (new Exception("参数名格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["type"]!=null)
		{
			
			if(Controls["type"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["type"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{type=(v==""?consts.int_min:Convert.ToInt32(v));}
				catch
				{
					 Controls["type"].Focus();
					throw  (new Exception("数据类型格式不正确！！"));
				}
				
			}
			else
			{
				try{type=(Controls["type"].Text==""?consts.int_min:Convert.ToInt32(Controls["type"].Text));}
				catch
				{
					 Controls["type"].Focus();
					throw  (new Exception("数据类型格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["catalog"]!=null)
		{
			
			if(Controls["catalog"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["catalog"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{catalog=(v==""?consts.int_min:Convert.ToInt32(v));}
				catch
				{
					 Controls["catalog"].Focus();
					throw  (new Exception("参数类别格式不正确！！"));
				}
				
			}
			else
			{
				try{catalog=(Controls["catalog"].Text==""?consts.int_min:Convert.ToInt32(Controls["catalog"].Text));}
				catch
				{
					 Controls["catalog"].Focus();
					throw  (new Exception("参数类别格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["value"]!=null)
		{
			
			if(Controls["value"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["value"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{value=v;}
				catch
				{
					 Controls["value"].Focus();
					throw  (new Exception("参数值格式不正确！！"));
				}
				
			}
			else
			{
				try{value=Controls["value"].Text;}
				catch
				{
					 Controls["value"].Focus();
					throw  (new Exception("参数值格式不正确！！"));
				}
				
			}
				
				
		}
			return true;
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
            
        }
    }
    

}

}
